package com.example.common.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.system.dao.UserDao;
import com.example.common.system.entity.RoleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.util.PageUtils;

import com.example.common.system.entity.UserEntity;
import com.example.common.system.service.UserService;

import java.util.List;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public PageUtils queryPage(Page<UserEntity> page, UserEntity userEntity) {
        IPage<UserEntity> result = this.page(page, new QueryWrapper<UserEntity>(userEntity));

        return new PageUtils(result.getRecords(),
                result.getTotal(),
                result.getSize(),
                result.getPages());
    }

    @Override
    public UserEntity queryByUserName(String username) {
        return userDao.queryByUserName(username);
    }

    @Override
    public List<RoleEntity> getRolesByUid(Long id) {
        return userDao.getRolesByUid(id);
    }

    @Override
    public Integer updateByUserName(String username, String newPassword) {
        return userDao.updateByUserName(username, newPassword);
    }
}